package dao

import (
	"context"
	"inventory/internal/model"
)

// FindBomByStorageKeys 通过storage_key 获取bom
func (d *Dao) FindBomStorageKeysBySgID(ctx context.Context, sgID uint32) (storageKeys []string, err error) {
	var boms []struct {
		StorageKey string `json:"storage_key"`
	}
	if err = d.TransContext(ctx).Model(&model.BomConfig{}).Select("storage_key").Where(
		"sg_id = ? and status = 1", sgID).Group("storage_key").Find(&boms).Error; err != nil {
		return
	}
	storageKeys = make([]string, len(boms))
	for i, bom := range boms {
		storageKeys[i] = bom.StorageKey
	}
	return
}
